import java.util.Scanner;

public class Demo21 {
    public static void main(String[] args) {
        Object locker=new Object();
        Thread t1=new Thread(()->{
            synchronized (locker){
                System.out.println("t1wait之前：");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1wait之后：");
        });
        Thread t2=new Thread(()->{
            synchronized (locker){
                System.out.println("t2wait之前：");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t2wait之后：");
        });
        Thread t3=new Thread(()->{
            synchronized (locker){
                System.out.println("t3wait之前：");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t3wait之后：");
        });
        Thread t4=new Thread(()->{
            synchronized (locker){
                System.out.println("t4wait之前：");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t4wait之后：");
        });
        t1.start();
        t2.start();
        t3.start();
        t4.start();
        Thread t5=new Thread(()->{
            synchronized (locker){
                System.out.println("notify之前：");
                Scanner scanner=new Scanner(System.in);
                scanner.next();
                //locker.notify(); 随即唤醒一个wait的线程
                locker.notifyAll();    //唤醒全部wait的线程
                System.out.println("notify之后：");
            }
        });
        t5.start();
    }
}
